home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / Classes / RCString / rationale < prev    next >
Text File  |  1995-06-12  |  2KB  |  73 lines

  1. It seems to me that since we can make a Class have anything we want, and we
  2. know that people love to argue about the merits of C-style, null terminated
  3. strings vs. Pascal-style "counted" strings, the Obj-C String class ought to
  4. be both.  That way we've got the flexiblity of null-termination, and
  5. the efficiency of knowing the string length up front.  The fact that it's an
  6. object should relieve problems with Pascal-style counted strings: we can use
  7. any size representation of the string length we want, not just the initial
  8. byte.
  9.  
  10. So, keeping length of string around in an instance var should minimize calls
  11. to strlen(), which are bound to get expensive.  It should also allow the
  12. use of bcopy() instead of strcpy().  Hopefully, vendors C library bcopy()
  13. will be cognizant of cache blocking, loop unrolling and so forth, and will
  14. be faster than strcpy().
  15.  
  16. The other thing that's really expensive about both C and Pascal style strings
  17. is memory allocation/deallocation.  The obvious solution to that is "refence
  18. counting."  Reference counting makes the object 'copy-on-write', I guess.
  19. It should minimize calls to bcopy(), malloc() and free().
  20.  
  21. Here's my String class wish list:
  22. -------------------------------------------------------------------------------
  23. reqs:
  24.     speedy
  25.     memory efficient
  26.     convenient
  27.     dynamically allocate/deallocate memory for string usage
  28.     robust (in face of programmer errors)
  29.  
  30. methods:
  31.  
  32.     new
  33.     new from another String object
  34.     new from ASCIIZ string
  35.     new filled with arbitrary number of arbitrary char
  36.  
  37.     free
  38.  
  39.     get pointer to real data
  40.  
  41.     empty out the real data
  42.  
  43.     get string length (printing size or memory allocated?)
  44.  
  45.     test for null string
  46.  
  47.     uppercase String
  48.     lowercase String
  49.  
  50.     replace with a new ASCIIZ string
  51.     replace with a new String object
  52.  
  53.     lexicographical comparison with another String object
  54.     lexicographical comparison with ASCIIZ string
  55.     case sensitive/case insensitive versions?
  56.  
  57.     append/prepend/insert another String object
  58.     append/prepend/insert ASCIIZ string
  59.  
  60.     retrieve substring at arbitrary position
  61.     retrieve substring matching a regexp
  62.     replace substring matching a regexp with ASCIIZ string
  63.     replace substring matching a regexp with another String object
  64.  
  65.     retrieve a char at arbitrary position
  66.     substitute a char at arbitrary position
  67.     insert a char at arbitrary position
  68.  
  69.     find index location of arbitrary char (from beginning and end of String)
  70.  
  71.     (BOOLEAN)matches a regexp or not
  72.  
  73.